﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WindowsFormsApplication1
{
    public class Deck
    {
        private List<Card> cards;
        private Random random = new Random();


        public Deck()
        {
            cards = new List<Card>();

            for(int i = 0; i < 4; i++)
                for(int j = 1; j < 14; j++)
                    this.cards.Add(new Card((Card.Suits)i, (Card.Values)j));
        }

        public Deck(Card[] cards)
        {
            this.cards = new List<Card>(cards);
        }

        public int Count { get { return cards.Count; } }

        public void Add(Card cardToAdd)
        {
            cards.Add(cardToAdd);
        }

        public Card Deal(int index)
        {
            Card cardToDeal = cards[index];
            cards.RemoveAt(index);
            return cardToDeal;
        }

        public void Shuffle()
        {
            List<Card> newCards = new List<Card>();

            while (cards.Count > 0)
            {
                int CardToMove = random.Next(cards.Count);
                newCards.Add(cards[CardToMove]);
                cards.RemoveAt(CardToMove);
            }

            cards = newCards;
        }

        public string[] GetCardNames()
        {
            string[] cardNames = new string[cards.Count];

            for (int i = 0; i < cards.Count; i++)
                cardNames[i] = cards[i].Name;

            return cardNames;
        }

        public void Sort()
        {
            cards.Sort(new CardComparer_BySuit());
        }
    }
}
